import os

import tornado.web
import tornado.ioloop
from tornado.options import define,options,parse_command_line
from app.views import(
    IndexHandler,
    XindexHandler,
    DbHandler,
    DelHandler,
    AddstuHandler,
    StuHandler
)

define('port',default=8080,type=int)


def make_app():
    return tornado.web.Application(handlers=[
        (r'/',IndexHandler),
        (r'/xindex/',XindexHandler),
        (r'/init_db/',DbHandler),
        (r'/drop_db/',DelHandler),
        (r'/add_stu/',AddstuHandler),
        (r'/stu/',StuHandler),

    ],template_path=os.path.join(os.path.dirname(__file__),'templates'),autoreload=True,debug=True,
        static_path=os.path.join(os.path.dirname(__file__),'static'))


if __name__ == "__main__":
    #解析命令行
    parse_command_line()
    #生成application对象
    app = make_app()

    #监听端口
    app.listen(options.port)

    #启动
    tornado.ioloop.IOLoop.current().start()
